package com.cykj.user.controller;

import com.cykj.common.core.web.controller.BaseController;
import com.cykj.common.core.web.domain.AjaxResult;
import com.cykj.user.dto.UserDTO;
import com.cykj.user.service.ICollectService;
import com.cykj.user.service.IHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.cykj.common.core.web.domain.AjaxResult.success;

/**
 * @BelongsProject: Cykj-Order-System
 * @BelongsPackage: com.cykj.user.controller
 * @Author: cwx
 * @CreateTime: 2025/8/30 13:39
 * @Description: 收藏
 * @Version: 1.0
 */
@RestController
@RequestMapping("/collect")
public class CollectController  extends BaseController {

    @Autowired
    private ICollectService collectService;
    // 添加收藏 (改为接收JSON)
    @PostMapping("/collect")
    public AjaxResult addCollectShop(@RequestBody UserDTO dto) {
        return toAjax(collectService.addCollectShop(dto.getBusinessId(), dto.getCustomerId()));
    }

    // 获取用户收藏店铺
    @GetMapping("/collect/list")
    public AjaxResult getCollectShops(@RequestParam Long customerId) {
        return success(collectService.getCollectShops(customerId));
    }

 /*   // 取消收藏 (两种方式)
    @DeleteMapping("/uncollect/{id}")
    public AjaxResult cancelCollectShop(@PathVariable Long id) {
        return toAjax(historyService.cancelCollectShop(id));
    }*/

    @DeleteMapping("/uncollect")
    public AjaxResult cancelCollectByBusinessAndCustomer(
            @RequestParam("businessId") Long businessId,
            @RequestParam("customerId") Long customerId) {
        return toAjax(collectService.cancelCollectByBusinessAndCustomer(businessId, customerId));
    }



    // 检查是否已收藏
    @GetMapping("/collect/check/{shopId}")
    public AjaxResult checkCollectStatus(
            @PathVariable Long shopId,
            @RequestParam Long userId
    ) {
        return success(collectService.checkCollectStatus(shopId, userId));
    }
}
